function message(message, status, data) {
  return JSON.stringify({
    message,
    status,
    data
  })
}

function Priority_Queue() {
  const q = [];
  this.pop = () => {
    try {
      return q.shift();
    } catch(e) {
      throw e;
    }
  }

  this.push = (item) => {
    const len = q.length;
    if(len === 0) {
      q.push(item);
    } else {
      let finished = false;
      for(let i = 0; i <= len - 1; i++) {
        if(item.priority <= q[i].priority) {
          finished = true;
          q.splice(i, 0, item);
          break;
        }
      }

      if(!finished) {
        q.push(item);
      }
    }

    this.shift = () => {
      try {
        return q.shift();
      } catch(e) {
        console.error(e);
      }
    }

    
  }
}


module.exports = {
  message,
  Priority_Queue
}